package com.Controller;

import com.Common.Result;
import com.Service.ProviderService;
import com.Util.RespUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description:
 * @author: hkw14
 * @time: 2021/5/7 12:04
 */
@WebServlet("/provider.do")
public class ProviderServlet extends HttpServlet {

    private static final long serialVersionUID = 8969996221493903436L;
    ProviderService providerService = new ProviderService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String type = req.getParameter("type");
        try {
            //利用反射调用方法
            this.getClass().getDeclaredMethod(type, HttpServletRequest.class,HttpServletResponse.class).invoke(this, req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void getList(HttpServletRequest req, HttpServletResponse resp){
        Result providerList = providerService.getProviderList();
        RespUtil.write(resp,providerList);
    }
}
